<template>
  <div>
    <div class="board" @click="showBoard" ref="board">
      {{ blackBoard }}
    </div>
    <div class="greenBoard" v-if="show || this.count === 2">
      <div class="blackBoard" @click="modifyBoard"></div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      count: 0,
      show: false,
      blackBoard: "黑板",
    };
  },
  methods: {
    showBoard() {
      this.count++;
      this.show = true;
      if (this.count === 0) {
        this.blackBoard = "黑板";
      } else if (this.count === 1) {
        this.blackBoard = "板中板";
      } else if (this.count === 2) {
        this.blackBoard = "黑板";
      } else {
        this.blackBoard = "黑板";
        this.count = 0;
        this.show = false;
      }
    },
    modifyBoard() {
      if (this.count === 2) {
        const black = document.querySelector(".blackBoard");
        black.style.width = "100%";
        black.style.height = "100%";
        black.style.right = "0";
        black.style.bottom = "0";
        this.count = 1;
        this.blackBoard = "板中板";
      }
    },
  },
  watch: {
    count(newVal, oldVal) {
      if (newVal === 2) {
        const black = document.querySelector(".blackBoard");
        black.style.width = "30%";
        black.style.height = "30%";
        black.style.right = "2%";
        black.style.bottom = "4%";
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.board {
  cursor: pointer;
  background: #4169e1;
  color: #fff;
  padding: 8px 12px;
  position: fixed;
  right: 24px;
  top: 50%;
  z-index: 10000001;
}
.greenBoard {
  width: 95%;
  height: 800px;
  margin: 0 auto;
  background-image: url("../assets/green.png");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  position: relative;
  .blackBoard {
    width: 100%;
    height: 100%;
    background-image: url("../assets/black.jpg");
    background-repeat: no-repeat;
    background-size: 100% 100%;
    position: absolute;
    z-index: 999;
  }
}
</style>
